#include <iostream>
using namespace std;
int n;
const int N = 40;
int a[N][N];
int flag[N][N];
int dx[4] = {0, -1, 0, 1};
int dy[4] = {1, 0, -1, 0};
void dfs(int x, int y) {
    for(int i = 0; i < 4; i++) {
        int row = x + dx[i], col = y + dy[i];
        if(row >= 0 && row < n && col >= 0 && col < n && flag[row][col] == 0 && a[row][col] == 0) {
            flag[row][col] = 1;
            dfs(row, col);
        }
    }
}
int main() {
    cin >> n;
    for(int i = 0; i < n; i++) {
        for(int j = 0; j < n; j++) {
            int t;
            cin >> t;
            a[i][j] = t;
        }
    }
    for(int i = 0; i < n; i++) {
        if(a[0][i] == 0)
        {
            flag[0][i] = 1;
            dfs(0, i);
        }
        if(a[n - 1][i] == 0) {
            flag[n - 1][i] = 1;
            dfs(n - 1, i);
        }
        if(a[i][0] == 0) {
            flag[i][0] = 1;
            dfs(i, 0);
        }
        if(a[i][n - 1] == 0) {
            flag[i][n - 1] = 1;
            dfs(i, n - 1);
        }
    }
    for(int i = 0; i < n; i++) {
        for(int j = 0; j < n; j++) {
            if(a[i][j] == 0 && flag[i][j] == 0) {
                cout << 2 << " ";
            }else {
                cout << a[i][j] << " ";
            }
        }
        cout << endl;
    }
    return 0;
}